<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OptionsPricing: testGBMPricingEngines.py Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OptionsPricing
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_c561bed9bc117923e059a4705c79b8c4.html">regression</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">testGBMPricingEngines.py</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">#!/usr/bin/python</span>
<a name="l00002"></a>00002 <span class="comment"># -*- coding: utf-8 -*-</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <span class="comment"># Copyright (c) 2011</span>
<a name="l00005"></a>00005 <span class="comment">#</span>
<a name="l00006"></a>00006 <span class="comment"># Permission is hereby granted, free of charge, to any person obtaining a</span>
<a name="l00007"></a>00007 <span class="comment"># copy of this software and associated documentation files (the &quot;Software&quot;),</span>
<a name="l00008"></a>00008 <span class="comment"># to deal in the Software without restriction, including without limitation</span>
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 <span class="comment"># the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
<a name="l00011"></a>00011 <span class="comment"># and/or sell copies of the Software, and to permit persons to whom the</span>
<a name="l00012"></a>00012 <span class="comment"># Software is furnished to do so, subject to the following conditions:</span>
<a name="l00013"></a>00013 <span class="comment"># The above copyright notice and this permission notice shall be included in</span>
<a name="l00014"></a>00014 <span class="comment"># all copies or substantial portions of the Software.</span>
<a name="l00015"></a>00015 <span class="comment">#</span>
<a name="l00016"></a>00016 <span class="comment"># THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<a name="l00017"></a>00017 <span class="comment"># IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00018"></a>00018 <span class="comment"># FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<a name="l00019"></a>00019 <span class="comment"># AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00020"></a>00020 <span class="comment"># LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<a name="l00021"></a>00021 <span class="comment"># OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE</span>
<a name="l00022"></a>00022 <span class="comment"># SOFTWARE.</span>
<a name="l00023"></a>00023 <span class="comment">#</span>
<a name="l00024"></a>00024 <span class="comment"># Author: Jesus Carrero &lt;j.o.carrero@gmail.com&gt;</span>
<a name="l00025"></a>00025 <span class="comment"># Mountain View, CA</span>
<a name="l00026"></a>00026 <span class="comment">#</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="keyword">from</span> scipy.linalg <span class="keyword">import</span> norm
<a name="l00029"></a>00029 <span class="keyword">from</span> scipy <span class="keyword">import</span> linspace, clip, exp
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="keyword">from</span> utils.FemBases <span class="keyword">import</span> LagrangeP1, LagrangeP2
<a name="l00032"></a>00032 <span class="keyword">from</span> input_output.DerivativePlots <span class="keyword">import</span> DerivativePlots
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <span class="keyword">import</span> models.NumericalOptionGBM <span class="keyword">as</span> nOp
<a name="l00035"></a>00035 <span class="keyword">from</span> models.AnalyticalFormulas <span class="keyword">import</span> vanillaCallPrice, \
<a name="l00036"></a>00036     vanillaPutPrice, cashOrNothingCall
<a name="l00037"></a>00037 
<a name="l00038"></a>00038 <span class="keyword">from</span> solvers.EuropeanTimeStepper <span class="keyword">import</span> EuropeanTimeStepper
<a name="l00039"></a>00039 <span class="keyword">from</span> solvers.AmericanTimeStepper <span class="keyword">import</span> AmericanTimeStepper
<a name="l00040"></a>00040 <span class="keyword">from</span> solvers.BermudamTimeStepper <span class="keyword">import</span> BermudamTimeStepper
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 <span class="keyword">import</span> unittest
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 
<a name="l00045"></a><a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html">00045</a> <span class="keyword">class </span><a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html">OptionsTestSuite</a>(unittest.TestCase):
<a name="l00046"></a>00046     <span class="stringliteral">&quot;&quot;&quot; Initialize all variables neede for the test. &quot;&quot;&quot;</span>
<a name="l00047"></a>00047 
<a name="l00048"></a><a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a2494ad88222726b4dbcea29cbbad49aa">00048</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a2494ad88222726b4dbcea29cbbad49aa">setUp</a>(self):
<a name="l00049"></a>00049         <span class="stringliteral">&quot;&quot;&quot; I don&#39;t know how to avoid this &quot;&quot;&quot;</span>
<a name="l00050"></a>00050 
<a name="l00051"></a>00051         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aa551351a81828f4311d5c588d8ca7855">m_r</a> = float(0.05)
<a name="l00052"></a>00052         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aaf2b13adbfec2eff494e176376ee8fe2">m_q</a> = 0.0
<a name="l00053"></a>00053         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a839be02e9aa09081c4009158e6f4e771">m_sigma</a> = float(0.4)
<a name="l00054"></a>00054         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0ca7d46e7305d5091d75228020d5ddb5">m_exp_time</a> = float(1.0)
<a name="l00055"></a>00055         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a3e6262110e65d0edbba0b53130efedb7">m_stock_price</a> = 40
<a name="l00056"></a>00056         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a> = 50
<a name="l00057"></a>00057 
<a name="l00058"></a>00058         (self.m_ntimestep_p1, self.m_nsegs_p1) = (200, 200)
<a name="l00059"></a>00059         (self.m_ntimestep_p2, self.m_nsegs_p2) = (200, 13)
<a name="l00060"></a>00060 
<a name="l00061"></a>00061         (self.m_smin, self.m_smax) = (10, 130)
<a name="l00062"></a>00062 
<a name="l00063"></a>00063         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0f12d66f8bd79b091ef69b43feea975a">m_plot</a> = <span class="keyword">True</span>
<a name="l00064"></a>00064         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a1c27784258519a1c5ebf516c6c254024">m_keep_hist</a> = <span class="keyword">True</span>
<a name="l00065"></a>00065         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#ac1de7acf599532cd7c858b8e09dadbf8">m_error_tol</a> = 0.12
<a name="l00066"></a>00066         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a116c2ddabdf64728c6e43197b7843d5e">m_price_engine</a> = <span class="keywordtype">None</span>
<a name="l00067"></a>00067         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a4d1a366ab73077f6f32e14a2d94ab6c1">m_lagrange_p1</a> = <a class="code" href="classutils_1_1FemBases_1_1LagrangeP1.html">LagrangeP1</a>()
<a name="l00068"></a>00068         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aa3e30a383ef42feb0f392f67eabe70f5">m_lagrange_p2</a> = LagrangeP2()
<a name="l00069"></a>00069 
<a name="l00070"></a>00070     <span class="keyword">def </span>_init_engine(self, option_style, shape_functions):
<a name="l00071"></a>00071         <span class="stringliteral">&quot;&quot;&quot; Instantiate the right engine base on the parameters. &quot;&quot;&quot;</span>
<a name="l00072"></a>00072 
<a name="l00073"></a>00073         nsegs = {<span class="stringliteral">&#39;P1&#39;</span>: self.m_nsegs_p1,
<a name="l00074"></a>00074                  <span class="stringliteral">&#39;P2&#39;</span>: self.m_nsegs_p2}[shape_functions]
<a name="l00075"></a>00075 
<a name="l00076"></a>00076         ntime_steps = {<span class="stringliteral">&#39;P1&#39;</span>: self.m_ntimestep_p1,
<a name="l00077"></a>00077                        <span class="stringliteral">&#39;P2&#39;</span>: self.m_ntimestep_p2}[shape_functions]
<a name="l00078"></a>00078 
<a name="l00079"></a>00079         <span class="keywordflow">if</span> <span class="stringliteral">&#39;E&#39;</span> == option_style:
<a name="l00080"></a>00080             self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a116c2ddabdf64728c6e43197b7843d5e">m_price_engine</a> = nOp.NumericalOptionGBM(
<a name="l00081"></a>00081                 <span class="stringliteral">&#39;E&#39;</span>,
<a name="l00082"></a>00082                 self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0ca7d46e7305d5091d75228020d5ddb5">m_exp_time</a>,
<a name="l00083"></a>00083                 self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a3e6262110e65d0edbba0b53130efedb7">m_stock_price</a>,
<a name="l00084"></a>00084                 self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a>,
<a name="l00085"></a>00085                 ntime_steps,
<a name="l00086"></a>00086                 nsegs,
<a name="l00087"></a>00087                 self.m_smin,
<a name="l00088"></a>00088                 self.m_smax,
<a name="l00089"></a>00089                 )
<a name="l00090"></a>00090         <span class="keywordflow">elif</span> <span class="stringliteral">&#39;A&#39;</span> == option_style:
<a name="l00091"></a>00091             self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a116c2ddabdf64728c6e43197b7843d5e">m_price_engine</a> = nOp.NumericalOptionGBM(
<a name="l00092"></a>00092                 <span class="stringliteral">&#39;A&#39;</span>,
<a name="l00093"></a>00093                 self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0ca7d46e7305d5091d75228020d5ddb5">m_exp_time</a>,
<a name="l00094"></a>00094                 self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a3e6262110e65d0edbba0b53130efedb7">m_stock_price</a>,
<a name="l00095"></a>00095                 self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a>,
<a name="l00096"></a>00096                 ntime_steps,
<a name="l00097"></a>00097                 nsegs,
<a name="l00098"></a>00098                 self.m_smin,
<a name="l00099"></a>00099                 self.m_smax,
<a name="l00100"></a>00100                 )
<a name="l00101"></a>00101         <span class="keywordflow">else</span>:
<a name="l00102"></a>00102             <span class="keyword">assert</span> <span class="keyword">False</span>
<a name="l00103"></a>00103 
<a name="l00104"></a>00104         is_real = <span class="keyword">True</span>
<a name="l00105"></a>00105         self.m_price_engine.set_option_cos(
<a name="l00106"></a>00106             self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a839be02e9aa09081c4009158e6f4e771">m_sigma</a>,
<a name="l00107"></a>00107             self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aaf2b13adbfec2eff494e176376ee8fe2">m_q</a>,
<a name="l00108"></a>00108             self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aa551351a81828f4311d5c588d8ca7855">m_r</a>,
<a name="l00109"></a>00109             is_real,
<a name="l00110"></a>00110             is_real,
<a name="l00111"></a>00111             is_real,
<a name="l00112"></a>00112             )
<a name="l00113"></a>00113 
<a name="l00114"></a>00114         <span class="comment"># self.m_price_engine.set_keep_hist(self.m_keep_hist)</span>
<a name="l00115"></a>00115 
<a name="l00116"></a>00116         <span class="keywordflow">if</span> <span class="stringliteral">&#39;P1&#39;</span> == shape_functions:
<a name="l00117"></a>00117             self.m_price_engine.set_shape_functions(self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a4d1a366ab73077f6f32e14a2d94ab6c1">m_lagrange_p1</a>)
<a name="l00118"></a>00118         <span class="keywordflow">elif</span> <span class="stringliteral">&#39;P2&#39;</span> == shape_functions:
<a name="l00119"></a>00119 
<a name="l00120"></a>00120             self.m_price_engine.set_shape_functions(self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aa3e30a383ef42feb0f392f67eabe70f5">m_lagrange_p2</a>)
<a name="l00121"></a>00121 
<a name="l00122"></a>00122     @classmethod
<a name="l00123"></a>00123     <span class="keyword">def </span>__init_plotter(cls, style, call_type, va_di):
<a name="l00124"></a>00124         <span class="stringliteral">&quot;&quot;&quot; Let plotter know what kind of data he&#39;ll be dealing with. &quot;&quot;&quot;</span>
<a name="l00125"></a>00125 
<a name="l00126"></a>00126 
<a name="l00127"></a>00127         title = {<span class="stringliteral">&#39;E&#39;</span>: <span class="stringliteral">&#39;European&#39;</span>, <span class="stringliteral">&#39;A&#39;</span>: <span class="stringliteral">&#39;American&#39;</span>,
<a name="l00128"></a>00128                  <span class="stringliteral">&#39;B&#39;</span>: <span class="stringliteral">&#39;Bermudam&#39;</span>}[style]
<a name="l00129"></a>00129         title += <span class="stringliteral">&#39; &#39;</span> + {<span class="stringliteral">&#39;P&#39;</span>: <span class="stringliteral">&#39;Put&#39;</span>, <span class="stringliteral">&#39;C&#39;</span>: <span class="stringliteral">&#39;Call&#39;</span>}[call_type] + <span class="stringliteral">&#39; &#39;</span> \
<a name="l00130"></a>00130             + va_di
<a name="l00131"></a>00131 
<a name="l00132"></a>00132         styles = {<span class="stringliteral">&#39;E&#39;</span>: <span class="stringliteral">&#39;Analytical&#39;</span>, <span class="stringliteral">&#39;A&#39;</span>: <span class="stringliteral">&#39;Euro-Analytical&#39;</span>,
<a name="l00133"></a>00133                   <span class="stringliteral">&#39;B&#39;</span>: <span class="stringliteral">&#39;Euro-Analytical&#39;</span>}[style]
<a name="l00134"></a>00134 
<a name="l00135"></a>00135         plt_engine = <a class="code" href="classinput__output_1_1DerivativePlots_1_1DerivativePlots.html">DerivativePlots</a>()
<a name="l00136"></a>00136         plt_engine.set_title(title)
<a name="l00137"></a>00137         plt_engine.set_curve_leyends([<span class="stringliteral">&#39;Numeric&#39;</span>, styles, <span class="stringliteral">&#39;Payoff&#39;</span>])
<a name="l00138"></a>00138 
<a name="l00139"></a>00139         plt_engine.set_axis_leyend({<span class="stringliteral">&#39;x&#39;</span>: <span class="stringliteral">&#39;Stoke Price&#39;</span>, <span class="stringliteral">&#39;y&#39;</span>: <span class="stringliteral">&#39;Option Price&#39;</span>
<a name="l00140"></a>00140                                })
<a name="l00141"></a>00141         <span class="keywordflow">return</span> plt_engine
<a name="l00142"></a>00142 
<a name="l00143"></a><a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5b3fcdeb8912ce62bdb56bcbae9438a4">00143</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5b3fcdeb8912ce62bdb56bcbae9438a4">plot_greeks</a>(self, stock_range, greeks, style, call_type):
<a name="l00144"></a>00144         <span class="stringliteral">&quot;&quot;&quot; Method for greeks. &quot;&quot;&quot;</span>
<a name="l00145"></a>00145 
<a name="l00146"></a>00146         plt_engine = self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0a63d756cc8383bace0ae3cd54348058">__init_plotter</a>(style, call_type, <span class="stringliteral">&#39;vanilla&#39;</span>)
<a name="l00147"></a>00147 
<a name="l00148"></a>00148         <span class="keywordflow">if</span> <span class="stringliteral">&#39;P&#39;</span> == call_type:
<a name="l00149"></a>00149             init_condition = clip(self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a> - stock_range, 0, 1e600)
<a name="l00150"></a>00150             call_vanilla_exact = vanillaPutPrice(stock_range,
<a name="l00151"></a>00151                     self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a>, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aa551351a81828f4311d5c588d8ca7855">m_r</a>, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a839be02e9aa09081c4009158e6f4e771">m_sigma</a>,
<a name="l00152"></a>00152                     self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0ca7d46e7305d5091d75228020d5ddb5">m_exp_time</a>)
<a name="l00153"></a>00153             plt_engine.set_leyend_posi(1)
<a name="l00154"></a>00154         <span class="keywordflow">else</span>:
<a name="l00155"></a>00155             init_condition = clip(stock_range - self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a>, 0, 1e600)
<a name="l00156"></a>00156             call_vanilla_exact = vanillaCallPrice(stock_range,
<a name="l00157"></a>00157                     self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a>, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aa551351a81828f4311d5c588d8ca7855">m_r</a>, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a839be02e9aa09081c4009158e6f4e771">m_sigma</a>,
<a name="l00158"></a>00158                     self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0ca7d46e7305d5091d75228020d5ddb5">m_exp_time</a>)
<a name="l00159"></a>00159             plt_engine.set_leyend_posi(2)
<a name="l00160"></a>00160         plt_engine.set_curves(stock_range, [greeks[:, 0], greeks[:, 1],
<a name="l00161"></a>00161                           greeks[:, 2]])
<a name="l00162"></a>00162         plt_engine.set_exit_time(1)
<a name="l00163"></a>00163         plt_engine.plot_greeks()
<a name="l00164"></a>00164 
<a name="l00165"></a>00165 
<a name="l00166"></a><a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a86c22ef8dfe3bbb1214413ec3d9a9102">00166</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a86c22ef8dfe3bbb1214413ec3d9a9102">plot_prices</a>(self, stock_range, instru_value, style, call_type,
<a name="l00167"></a>00167                     va_di=<span class="stringliteral">&#39;vanilla&#39;</span>):
<a name="l00168"></a>00168         <span class="stringliteral">&quot;&quot;&quot; Method for plotting price values. &quot;&quot;&quot;</span>
<a name="l00169"></a>00169 
<a name="l00170"></a>00170         plt_engine = self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0a63d756cc8383bace0ae3cd54348058">__init_plotter</a>(style, call_type, va_di)
<a name="l00171"></a>00171 
<a name="l00172"></a>00172         <span class="keywordflow">if</span> <span class="stringliteral">&#39;P&#39;</span> == call_type:
<a name="l00173"></a>00173             init_condition = clip(self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a> - stock_range, 0, 1e600)
<a name="l00174"></a>00174             <span class="keywordflow">if</span> <span class="stringliteral">&#39;digital&#39;</span> == call_type:
<a name="l00175"></a>00175                 init_condition[init_condition &gt; 0] = 1.0
<a name="l00176"></a>00176             call_analytical = vanillaPutPrice(stock_range,
<a name="l00177"></a>00177                     self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a>, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aa551351a81828f4311d5c588d8ca7855">m_r</a>, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a839be02e9aa09081c4009158e6f4e771">m_sigma</a>,
<a name="l00178"></a>00178                     self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0ca7d46e7305d5091d75228020d5ddb5">m_exp_time</a>)
<a name="l00179"></a>00179             plt_engine.set_leyend_posi(1)
<a name="l00180"></a>00180         <span class="keywordflow">else</span>:
<a name="l00181"></a>00181             init_condition = clip(stock_range - self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a>, 0, 1e600)
<a name="l00182"></a>00182             <span class="keywordflow">if</span> <span class="stringliteral">&#39;vanilla&#39;</span> == va_di:
<a name="l00183"></a>00183                 call_analytical = vanillaCallPrice(stock_range,
<a name="l00184"></a>00184                         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a>, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aa551351a81828f4311d5c588d8ca7855">m_r</a>, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a839be02e9aa09081c4009158e6f4e771">m_sigma</a>,
<a name="l00185"></a>00185                         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0ca7d46e7305d5091d75228020d5ddb5">m_exp_time</a>)
<a name="l00186"></a>00186                 plt_engine.set_leyend_posi(2)
<a name="l00187"></a>00187 
<a name="l00188"></a>00188             <span class="keywordflow">if</span> <span class="stringliteral">&#39;digital&#39;</span> == va_di:
<a name="l00189"></a>00189                 init_condition[init_condition &gt; 0] = 1.0
<a name="l00190"></a>00190                 call_analytical = cashOrNothingCall(stock_range,
<a name="l00191"></a>00191                         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a5131d2bf342c3002a2922946e11976eb">m_strike</a>, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#aa551351a81828f4311d5c588d8ca7855">m_r</a>, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a839be02e9aa09081c4009158e6f4e771">m_sigma</a>,
<a name="l00192"></a>00192                         self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0ca7d46e7305d5091d75228020d5ddb5">m_exp_time</a>)
<a name="l00193"></a>00193                 plt_engine.set_leyend_posi(1)
<a name="l00194"></a>00194 
<a name="l00195"></a>00195         plt_engine.set_curves(stock_range, [instru_value, call_analytical,
<a name="l00196"></a>00196                           init_condition])
<a name="l00197"></a>00197 
<a name="l00198"></a>00198         <span class="keywordflow">if</span> <span class="keyword">True</span> == self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a1c27784258519a1c5ebf516c6c254024">m_keep_hist</a>:
<a name="l00199"></a>00199             price_hist = self.m_price_engine.get_price_history()
<a name="l00200"></a>00200             plt_engine.set_history(stock_range, price_hist, self.<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html#a0ca7d46e7305d5091d75228020d5ddb5">m_exp_time</a>)
<a name="l00201"></a>00201             plt_engine.plot_history()
<a name="l00202"></a>00202         <span class="keywordflow">else</span>:
<a name="l00203"></a>00203             plt_engine.plot()
<a name="l00204"></a>00204 
<a name="l00205"></a>00205 
<a name="l00206"></a><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroCall.html">00206</a> <span class="keyword">class </span><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroCall.html">PlainVanillaEuroCall</a>(<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html">OptionsTestSuite</a>):
<a name="l00207"></a>00207     <span class="stringliteral">&quot;&quot;&quot; Plain vanilla. You can play with all the parameters :) &quot;&quot;&quot;</span>
<a name="l00208"></a>00208 
<a name="l00209"></a><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroCall.html#a2df64583e1279955145602fa02f08829">00209</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroCall.html#a2df64583e1279955145602fa02f08829">runTest</a>(self):
<a name="l00210"></a>00210         <span class="stringliteral">&quot;&quot;&quot; run regression test. &quot;&quot;&quot;</span>
<a name="l00211"></a>00211 
<a name="l00212"></a>00212         shape_functions = <span class="stringliteral">&#39;P2&#39;</span>
<a name="l00213"></a>00213         self._init_engine(<span class="stringliteral">&#39;E&#39;</span>, shape_functions)
<a name="l00214"></a>00214 
<a name="l00215"></a>00215         self.<a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroCall.html#a510e74ec0dcb4f6a29724cb585a765a1">m_keep_hist</a> = <span class="keyword">False</span>
<a name="l00216"></a>00216         time_stepper = <a class="code" href="classsolvers_1_1EuropeanTimeStepper_1_1EuropeanTimeStepper.html">EuropeanTimeStepper</a>()
<a name="l00217"></a>00217         time_stepper.set_number_steps(self.m_ntimestep_p2)
<a name="l00218"></a>00218         time_stepper.set_time2simulate(self.m_exp_time)
<a name="l00219"></a>00219         time_stepper.set_dolog(<span class="keyword">True</span>)
<a name="l00220"></a>00220         time_stepper.set_keep_hist(self.<a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroCall.html#a510e74ec0dcb4f6a29724cb585a765a1">m_keep_hist</a>)
<a name="l00221"></a>00221 
<a name="l00222"></a>00222         self.m_price_engine.set_price_mode(<span class="stringliteral">&#39;greeks&#39;</span>)
<a name="l00223"></a>00223         self.m_price_engine.set_time_stepper(time_stepper)
<a name="l00224"></a>00224 
<a name="l00225"></a>00225         (stock_range, greeks) = self.m_price_engine.price_call()
<a name="l00226"></a>00226 
<a name="l00227"></a>00227         <span class="keywordflow">if</span> self.m_plot:
<a name="l00228"></a>00228             self.plot_greeks(stock_range, greeks, <span class="stringliteral">&#39;E&#39;</span>, <span class="stringliteral">&#39;C&#39;</span>)
<a name="l00229"></a>00229 
<a name="l00230"></a>00230         call_vanilla_exact = vanillaCallPrice(stock_range,
<a name="l00231"></a>00231                 self.m_strike, self.m_r, self.m_sigma, self.m_exp_time)
<a name="l00232"></a>00232         call_vanilla_exact[call_vanilla_exact &lt; 1.0e-6] = 0.0
<a name="l00233"></a>00233         error_norm = norm(greeks[:, 0] - call_vanilla_exact)
<a name="l00234"></a>00234         <span class="keyword">assert</span> self.m_error_tol &gt; error_norm
<a name="l00235"></a>00235 
<a name="l00236"></a>00236 
<a name="l00237"></a><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroPut.html">00237</a> <span class="keyword">class </span><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroPut.html">PlainVanillaEuroPut</a>(<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html">OptionsTestSuite</a>):
<a name="l00238"></a>00238     <span class="stringliteral">&quot;&quot;&quot; Plain Put Euro style. &quot;&quot;&quot;</span>
<a name="l00239"></a>00239 
<a name="l00240"></a><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroPut.html#ab9678442e6967b48b3e33d1395b79bde">00240</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroPut.html#ab9678442e6967b48b3e33d1395b79bde">runTest</a>(self):
<a name="l00241"></a>00241         <span class="stringliteral">&quot;&quot;&quot; run test. &quot;&quot;&quot;</span>
<a name="l00242"></a>00242 
<a name="l00243"></a>00243         shape_functions = <span class="stringliteral">&#39;P2&#39;</span>
<a name="l00244"></a>00244         self._init_engine(<span class="stringliteral">&#39;E&#39;</span>, shape_functions)
<a name="l00245"></a>00245 
<a name="l00246"></a>00246         time_stepper = <a class="code" href="classsolvers_1_1EuropeanTimeStepper_1_1EuropeanTimeStepper.html">EuropeanTimeStepper</a>()
<a name="l00247"></a>00247         time_stepper.set_number_steps(self.m_ntimestep_p2)
<a name="l00248"></a>00248         time_stepper.set_time2simulate(self.m_exp_time)
<a name="l00249"></a>00249         time_stepper.set_dolog(<span class="keyword">True</span>)
<a name="l00250"></a>00250         time_stepper.set_keep_hist(self.m_keep_hist)
<a name="l00251"></a>00251 
<a name="l00252"></a>00252         self.m_price_engine.set_time_stepper(time_stepper)
<a name="l00253"></a>00253 
<a name="l00254"></a>00254         (stock_range, put_val) = self.m_price_engine.price_put()
<a name="l00255"></a>00255 
<a name="l00256"></a>00256         call_vanilla_exact = vanillaPutPrice(stock_range,
<a name="l00257"></a>00257                 self.m_strike, self.m_r, self.m_sigma, self.m_exp_time)
<a name="l00258"></a>00258 
<a name="l00259"></a>00259         <span class="keywordflow">if</span> self.m_plot:
<a name="l00260"></a>00260             self.plot_prices(stock_range, put_val, <span class="stringliteral">&#39;E&#39;</span>, <span class="stringliteral">&#39;P&#39;</span>)
<a name="l00261"></a>00261 
<a name="l00262"></a>00262         call_vanilla_exact[call_vanilla_exact &lt; 1.0e-6] = 0.0
<a name="l00263"></a>00263         error_norm = norm(put_val - call_vanilla_exact)
<a name="l00264"></a>00264         <span class="keyword">assert</span> self.m_error_tol &gt; error_norm
<a name="l00265"></a>00265 
<a name="l00266"></a>00266 
<a name="l00267"></a><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaAmerPut.html">00267</a> <span class="keyword">class </span><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaAmerPut.html">PlainVanillaAmerPut</a>(<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html">OptionsTestSuite</a>):
<a name="l00268"></a>00268     <span class="stringliteral">&quot;&quot;&quot; American Put plain vanilla. &quot;&quot;&quot;</span>
<a name="l00269"></a>00269 
<a name="l00270"></a><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaAmerPut.html#abe7ff1c6da8f712aa06b000124633a7e">00270</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaAmerPut.html#abe7ff1c6da8f712aa06b000124633a7e">runTest</a>(self):
<a name="l00271"></a>00271         <span class="stringliteral">&quot;&quot;&quot; run test. &quot;&quot;&quot;</span>
<a name="l00272"></a>00272 
<a name="l00273"></a>00273         shape_functions = <span class="stringliteral">&#39;P2&#39;</span>
<a name="l00274"></a>00274         self._init_engine(<span class="stringliteral">&#39;A&#39;</span>, shape_functions)
<a name="l00275"></a>00275 
<a name="l00276"></a>00276         time_stepper = <a class="code" href="classsolvers_1_1AmericanTimeStepper_1_1AmericanTimeStepper.html">AmericanTimeStepper</a>()
<a name="l00277"></a>00277         time_stepper.set_number_steps(self.m_ntimestep_p2)
<a name="l00278"></a>00278         time_stepper.set_time2simulate(self.m_exp_time)
<a name="l00279"></a>00279         time_stepper.set_dolog(<span class="keyword">True</span>)
<a name="l00280"></a>00280         time_stepper.set_keep_hist(self.m_keep_hist)
<a name="l00281"></a>00281 
<a name="l00282"></a>00282         self.m_price_engine.set_time_stepper(time_stepper)
<a name="l00283"></a>00283 
<a name="l00284"></a>00284         (stock_range, put_val) = self.m_price_engine.price_put()
<a name="l00285"></a>00285 
<a name="l00286"></a>00286         <span class="keywordflow">if</span> self.m_plot:
<a name="l00287"></a>00287             self.plot_prices(stock_range, put_val, <span class="stringliteral">&#39;A&#39;</span>, <span class="stringliteral">&#39;P&#39;</span>)
<a name="l00288"></a>00288 
<a name="l00289"></a>00289         <span class="comment"># no analytincal formula to compare.</span>
<a name="l00290"></a>00290 
<a name="l00291"></a>00291         <span class="keyword">assert</span> <span class="keyword">True</span>
<a name="l00292"></a>00292 
<a name="l00293"></a>00293 
<a name="l00294"></a><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaAmerCall.html">00294</a> <span class="keyword">class </span><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaAmerCall.html">PlainVanillaAmerCall</a>(<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html">OptionsTestSuite</a>):
<a name="l00295"></a>00295     <span class="stringliteral">&quot;&quot;&quot; American call option. &quot;&quot;&quot;</span>
<a name="l00296"></a>00296 
<a name="l00297"></a><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaAmerCall.html#a0185c459092b3d828fa3c89d48c25ce9">00297</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaAmerCall.html#a0185c459092b3d828fa3c89d48c25ce9">runTest</a>(self):
<a name="l00298"></a>00298         <span class="stringliteral">&quot;&quot;&quot; run test. &quot;&quot;&quot;</span>
<a name="l00299"></a>00299 
<a name="l00300"></a>00300         shape_functions = <span class="stringliteral">&#39;P2&#39;</span>
<a name="l00301"></a>00301         self._init_engine(<span class="stringliteral">&#39;A&#39;</span>, shape_functions)
<a name="l00302"></a>00302 
<a name="l00303"></a>00303         time_stepper = <a class="code" href="classsolvers_1_1AmericanTimeStepper_1_1AmericanTimeStepper.html">AmericanTimeStepper</a>()
<a name="l00304"></a>00304         time_stepper.set_number_steps(self.m_ntimestep_p2 + 50)
<a name="l00305"></a>00305         time_stepper.set_time2simulate(self.m_exp_time)
<a name="l00306"></a>00306         time_stepper.set_dolog(<span class="keyword">True</span>)
<a name="l00307"></a>00307         time_stepper.set_keep_hist(self.m_keep_hist)
<a name="l00308"></a>00308 
<a name="l00309"></a>00309         self.m_price_engine.set_time_stepper(time_stepper)
<a name="l00310"></a>00310 
<a name="l00311"></a>00311         (stock_range, call_val) = self.m_price_engine.price_call()
<a name="l00312"></a>00312 
<a name="l00313"></a>00313         <span class="keywordflow">if</span> self.m_plot:
<a name="l00314"></a>00314             self.plot_prices(stock_range, call_val, <span class="stringliteral">&#39;A&#39;</span>, <span class="stringliteral">&#39;C&#39;</span>)
<a name="l00315"></a>00315 
<a name="l00316"></a>00316         call_vanilla_exact = vanillaCallPrice(stock_range,
<a name="l00317"></a>00317                 self.m_strike, self.m_r, self.m_sigma, self.m_exp_time)
<a name="l00318"></a>00318         call_vanilla_exact[call_vanilla_exact &lt; 1.0e-6] = 0.0
<a name="l00319"></a>00319         error_norm = norm(call_val - call_vanilla_exact)
<a name="l00320"></a>00320         <span class="keyword">assert</span> self.m_error_tol &gt; error_norm
<a name="l00321"></a>00321 
<a name="l00322"></a>00322 
<a name="l00323"></a><a class="code" href="classtestGBMPricingEngines_1_1BermudamCall.html">00323</a> <span class="keyword">class </span><a class="code" href="classtestGBMPricingEngines_1_1BermudamCall.html">BermudamCall</a>(<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html">OptionsTestSuite</a>):
<a name="l00324"></a>00324     <span class="stringliteral">&quot;&quot;&quot; Bermudan call vanilla. &quot;&quot;&quot;</span>
<a name="l00325"></a>00325 
<a name="l00326"></a><a class="code" href="classtestGBMPricingEngines_1_1BermudamCall.html#a555a94dbbce3ca6e4903efc166cdf385">00326</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1BermudamCall.html#a555a94dbbce3ca6e4903efc166cdf385">runTest</a>(self):
<a name="l00327"></a>00327         <span class="stringliteral">&quot;&quot;&quot; run test. &quot;&quot;&quot;</span>
<a name="l00328"></a>00328 
<a name="l00329"></a>00329         shape_functions = <span class="stringliteral">&#39;P2&#39;</span>
<a name="l00330"></a>00330         self._init_engine(<span class="stringliteral">&#39;E&#39;</span>, shape_functions)
<a name="l00331"></a>00331 
<a name="l00332"></a>00332         exercise_dates = linspace(0.2, self.m_exp_time, 3, <span class="keyword">False</span>)
<a name="l00333"></a>00333 
<a name="l00334"></a>00334         self.<a class="code" href="classtestGBMPricingEngines_1_1BermudamCall.html#a9c0769c4af4418563c119a8a2a857fd2">m_keep_hist</a> = <span class="keyword">False</span>
<a name="l00335"></a>00335         time_stepper = <a class="code" href="classsolvers_1_1BermudamTimeStepper_1_1BermudamTimeStepper.html">BermudamTimeStepper</a>()
<a name="l00336"></a>00336         time_stepper.set_number_steps(self.m_ntimestep_p2)
<a name="l00337"></a>00337         time_stepper.set_time2simulate(self.m_exp_time)
<a name="l00338"></a>00338         time_stepper.set_exercise_dates(exercise_dates)
<a name="l00339"></a>00339         time_stepper.set_dolog(<span class="keyword">True</span>)
<a name="l00340"></a>00340         time_stepper.set_keep_hist(self.<a class="code" href="classtestGBMPricingEngines_1_1BermudamCall.html#a9c0769c4af4418563c119a8a2a857fd2">m_keep_hist</a>)
<a name="l00341"></a>00341 
<a name="l00342"></a>00342         self.m_price_engine.set_time_stepper(time_stepper)
<a name="l00343"></a>00343 
<a name="l00344"></a>00344         (stock_range, call_val) = self.m_price_engine.price_call()
<a name="l00345"></a>00345 
<a name="l00346"></a>00346         <span class="keywordflow">if</span> self.m_plot:
<a name="l00347"></a>00347             self.plot_prices(stock_range, call_val, <span class="stringliteral">&#39;B&#39;</span>, <span class="stringliteral">&#39;C&#39;</span>)
<a name="l00348"></a>00348 
<a name="l00349"></a>00349         call_value = vanillaCallPrice(stock_range, self.m_strike,
<a name="l00350"></a>00350                 self.m_r, self.m_sigma, self.m_exp_time)
<a name="l00351"></a>00351         call_value[call_value &lt; 1.0e-6] = 0.0
<a name="l00352"></a>00352         error_norm = norm(call_val - call_value)
<a name="l00353"></a>00353         <span class="keyword">assert</span> self.m_error_tol &gt; error_norm
<a name="l00354"></a>00354 
<a name="l00355"></a>00355 
<a name="l00356"></a><a class="code" href="classtestGBMPricingEngines_1_1BermudamPut.html">00356</a> <span class="keyword">class </span><a class="code" href="classtestGBMPricingEngines_1_1BermudamPut.html">BermudamPut</a>(<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html">OptionsTestSuite</a>):
<a name="l00357"></a>00357     <span class="stringliteral">&quot;&quot;&quot; Bermudam put vanilla. &quot;&quot;&quot;</span>
<a name="l00358"></a>00358 
<a name="l00359"></a><a class="code" href="classtestGBMPricingEngines_1_1BermudamPut.html#ac4234d78a5deca6a6159583412efc79f">00359</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1BermudamPut.html#ac4234d78a5deca6a6159583412efc79f">runTest</a>(self):
<a name="l00360"></a>00360         <span class="stringliteral">&quot;&quot;&quot; run test. &quot;&quot;&quot;</span>
<a name="l00361"></a>00361 
<a name="l00362"></a>00362         shape_functions = <span class="stringliteral">&#39;P2&#39;</span>
<a name="l00363"></a>00363         self._init_engine(<span class="stringliteral">&#39;E&#39;</span>, shape_functions)
<a name="l00364"></a>00364 
<a name="l00365"></a>00365         exercise_dates = linspace(0.2, self.m_exp_time, 3, <span class="keyword">False</span>)
<a name="l00366"></a>00366 
<a name="l00367"></a>00367         self.<a class="code" href="classtestGBMPricingEngines_1_1BermudamPut.html#a3acddf9b66d89e731ed34ae03547fcd0">m_keep_hist</a> = <span class="keyword">False</span>
<a name="l00368"></a>00368         time_stepper = <a class="code" href="classsolvers_1_1BermudamTimeStepper_1_1BermudamTimeStepper.html">BermudamTimeStepper</a>()
<a name="l00369"></a>00369         time_stepper.set_number_steps(self.m_ntimestep_p2)
<a name="l00370"></a>00370         time_stepper.set_time2simulate(self.m_exp_time)
<a name="l00371"></a>00371         time_stepper.set_exercise_dates(exercise_dates)
<a name="l00372"></a>00372         time_stepper.set_dolog(<span class="keyword">True</span>)
<a name="l00373"></a>00373         time_stepper.set_keep_hist(self.<a class="code" href="classtestGBMPricingEngines_1_1BermudamPut.html#a3acddf9b66d89e731ed34ae03547fcd0">m_keep_hist</a>)
<a name="l00374"></a>00374 
<a name="l00375"></a>00375         self.m_price_engine.set_time_stepper(time_stepper)
<a name="l00376"></a>00376 
<a name="l00377"></a>00377         (stock_range, call_val) = self.m_price_engine.price_put()
<a name="l00378"></a>00378 
<a name="l00379"></a>00379         <span class="keywordflow">if</span> self.m_plot:
<a name="l00380"></a>00380             self.plot_prices(stock_range, call_val, <span class="stringliteral">&#39;B&#39;</span>, <span class="stringliteral">&#39;P&#39;</span>)
<a name="l00381"></a>00381 
<a name="l00382"></a>00382         put_vanilla_value = vanillaPutPrice(stock_range, self.m_strike,
<a name="l00383"></a>00383                 self.m_r, self.m_sigma, self.m_exp_time)
<a name="l00384"></a>00384         put_vanilla_value[put_vanilla_value &lt; 1.0e-6] = 0.0
<a name="l00385"></a>00385 
<a name="l00386"></a>00386         <span class="comment"># no analytincal formulat to compare.</span>
<a name="l00387"></a>00387 
<a name="l00388"></a>00388         <span class="keyword">assert</span> <span class="keyword">True</span>
<a name="l00389"></a>00389 
<a name="l00390"></a>00390 
<a name="l00391"></a><a class="code" href="classtestGBMPricingEngines_1_1DigitalEuroCall.html">00391</a> <span class="keyword">class </span><a class="code" href="classtestGBMPricingEngines_1_1DigitalEuroCall.html">DigitalEuroCall</a>(<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html">OptionsTestSuite</a>):
<a name="l00392"></a>00392 
<a name="l00393"></a>00393     <span class="stringliteral">&quot;&quot;&quot; Numerical digital functions. &quot;&quot;&quot;</span>
<a name="l00394"></a>00394 
<a name="l00395"></a><a class="code" href="classtestGBMPricingEngines_1_1DigitalEuroCall.html#a9b0380264425a0dec1f1be5dffad0bbb">00395</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1DigitalEuroCall.html#a9b0380264425a0dec1f1be5dffad0bbb">runTest</a>(self):
<a name="l00396"></a>00396         <span class="stringliteral">&quot;&quot;&quot; follow this steps to call the engine. &quot;&quot;&quot;</span>
<a name="l00397"></a>00397 
<a name="l00398"></a>00398         shape_functions = <span class="stringliteral">&#39;P2&#39;</span>
<a name="l00399"></a>00399         self._init_engine(<span class="stringliteral">&#39;E&#39;</span>, shape_functions)
<a name="l00400"></a>00400 
<a name="l00401"></a>00401         self.<a class="code" href="classtestGBMPricingEngines_1_1DigitalEuroCall.html#a949ca9d87ef83fa08b1de3d49fe0f36a">m_keep_hist</a> = <span class="keyword">False</span>
<a name="l00402"></a>00402         time_stepper = <a class="code" href="classsolvers_1_1EuropeanTimeStepper_1_1EuropeanTimeStepper.html">EuropeanTimeStepper</a>()
<a name="l00403"></a>00403         time_stepper.set_number_steps(self.m_ntimestep_p2)
<a name="l00404"></a>00404         time_stepper.set_time2simulate(self.m_exp_time)
<a name="l00405"></a>00405         time_stepper.set_dolog(<span class="keyword">True</span>)
<a name="l00406"></a>00406         time_stepper.set_keep_hist(self.<a class="code" href="classtestGBMPricingEngines_1_1DigitalEuroCall.html#a949ca9d87ef83fa08b1de3d49fe0f36a">m_keep_hist</a>)
<a name="l00407"></a>00407 
<a name="l00408"></a>00408         self.m_price_engine.set_contract_type(<span class="stringliteral">&#39;digital&#39;</span>)
<a name="l00409"></a>00409         self.m_price_engine.set_time_stepper(time_stepper)
<a name="l00410"></a>00410 
<a name="l00411"></a>00411         (stock_range, call_val) = self.m_price_engine.price_call()
<a name="l00412"></a>00412 
<a name="l00413"></a>00413         <span class="keywordflow">if</span> self.m_plot:
<a name="l00414"></a>00414             self.plot_prices(stock_range, call_val, <span class="stringliteral">&#39;E&#39;</span>, <span class="stringliteral">&#39;C&#39;</span>, <span class="stringliteral">&#39;digital&#39;</span>)
<a name="l00415"></a>00415 
<a name="l00416"></a>00416         call_digital_value = cashOrNothingCall(stock_range,
<a name="l00417"></a>00417                 self.m_strike, self.m_r, self.m_sigma, self.m_exp_time)
<a name="l00418"></a>00418         call_digital_value[call_digital_value &lt; 1.0e-6] = 0.0
<a name="l00419"></a>00419         error_norm = norm(call_val - call_digital_value)
<a name="l00420"></a>00420         <span class="keyword">assert</span> self.m_error_tol &gt; error_norm
<a name="l00421"></a>00421 
<a name="l00422"></a>00422 
<a name="l00423"></a><a class="code" href="classtestGBMPricingEngines_1_1PutCallParity.html">00423</a> <span class="keyword">class </span><a class="code" href="classtestGBMPricingEngines_1_1PutCallParity.html">PutCallParity</a>(<a class="code" href="classtestGBMPricingEngines_1_1OptionsTestSuite.html">OptionsTestSuite</a>):
<a name="l00424"></a>00424     <span class="stringliteral">&quot;&quot;&quot; Consitency test. &quot;&quot;&quot;</span>
<a name="l00425"></a>00425 
<a name="l00426"></a><a class="code" href="classtestGBMPricingEngines_1_1PutCallParity.html#a31d7a7b93ab2de318d530c4c46c2dc7b">00426</a>     <span class="keyword">def </span><a class="code" href="classtestGBMPricingEngines_1_1PutCallParity.html#a31d7a7b93ab2de318d530c4c46c2dc7b">runTest</a>(self):
<a name="l00427"></a>00427         <span class="stringliteral">&quot;&quot;&quot; test put call parity. &quot;&quot;&quot;</span>
<a name="l00428"></a>00428 
<a name="l00429"></a>00429         shape_functions = <span class="stringliteral">&#39;P1&#39;</span>
<a name="l00430"></a>00430         self._init_engine(<span class="stringliteral">&#39;E&#39;</span>, shape_functions)
<a name="l00431"></a>00431 
<a name="l00432"></a>00432         time_stepper = <a class="code" href="classsolvers_1_1EuropeanTimeStepper_1_1EuropeanTimeStepper.html">EuropeanTimeStepper</a>()
<a name="l00433"></a>00433         time_stepper.set_number_steps(self.m_ntimestep_p1)
<a name="l00434"></a>00434         time_stepper.set_time2simulate(self.m_exp_time)
<a name="l00435"></a>00435         time_stepper.set_dolog(<span class="keyword">True</span>)
<a name="l00436"></a>00436         time_stepper.set_keep_hist(self.m_keep_hist)
<a name="l00437"></a>00437 
<a name="l00438"></a>00438         self.m_price_engine.set_time_stepper(time_stepper)
<a name="l00439"></a>00439 
<a name="l00440"></a>00440         (stock_range, put_val) = self.m_price_engine.price_put()
<a name="l00441"></a>00441         (stock_range, call_val) = self.m_price_engine.price_call()
<a name="l00442"></a>00442 
<a name="l00443"></a>00443         error = call_val - put_val - stock_range + exp(-self.m_r
<a name="l00444"></a>00444                                 * self.m_exp_time) * self.m_strike
<a name="l00445"></a>00445         <span class="keyword">assert</span> self.m_error_tol &gt; max(abs(error))
<a name="l00446"></a>00446 
<a name="l00447"></a>00447 
<a name="l00448"></a>00448 <span class="keyword">def </span>my_suite():
<a name="l00449"></a>00449     <span class="stringliteral">&quot;&quot;&quot; add new regression test here. &quot;&quot;&quot;</span>
<a name="l00450"></a>00450 
<a name="l00451"></a>00451     suite = unittest.TestSuite()
<a name="l00452"></a>00452 
<a name="l00453"></a>00453     suite.addTest(<a class="code" href="classtestGBMPricingEngines_1_1BermudamPut.html">BermudamPut</a>())
<a name="l00454"></a>00454     suite.addTest(<a class="code" href="classtestGBMPricingEngines_1_1BermudamCall.html">BermudamCall</a>())
<a name="l00455"></a>00455     suite.addTest(<a class="code" href="classtestGBMPricingEngines_1_1PutCallParity.html">PutCallParity</a>())
<a name="l00456"></a>00456     suite.addTest(<a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroCall.html">PlainVanillaEuroCall</a>())
<a name="l00457"></a>00457     suite.addTest(<a class="code" href="classtestGBMPricingEngines_1_1DigitalEuroCall.html">DigitalEuroCall</a>())
<a name="l00458"></a>00458     suite.addTest(<a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaEuroPut.html">PlainVanillaEuroPut</a>())
<a name="l00459"></a>00459     suite.addTest(<a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaAmerCall.html">PlainVanillaAmerCall</a>())
<a name="l00460"></a>00460     suite.addTest(<a class="code" href="classtestGBMPricingEngines_1_1PlainVanillaAmerPut.html">PlainVanillaAmerPut</a>())
<a name="l00461"></a>00461 
<a name="l00462"></a>00462     <span class="keywordflow">return</span> suite
<a name="l00463"></a>00463 
<a name="l00464"></a>00464 
<a name="l00465"></a>00465 <span class="keywordflow">if</span> __name__ == <span class="stringliteral">&#39;__main__&#39;</span>:
<a name="l00466"></a>00466 
<a name="l00467"></a>00467     runner = unittest.TextTestRunner(verbosity=2)
<a name="l00468"></a>00468     result = runner.run(my_suite())
<a name="l00469"></a>00469 
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Dec 22 2011 05:17:53 for OptionsPricing by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
